#include "test3.hpp"
#include "VmModel.hpp"
#include "config.hpp"
#include "rander.hpp"
#include <cstdio>

static void print_helper(std::vector<int> const &requests, int page_fault,
                         int n_mem) {
  printf("%d\t\t%d\t\t%f\n", n_mem, page_fault,
         1 - float(page_fault) / requests.size());
}

void test3_helper(ALGO algo, int request_size, int n_mem) {
  rander rander(0, VM_N_BLOCK - 1);
  std::vector<int> requests(rander.get_rand_vector(request_size));

  VmModel vmModel(PAGE_SIZE, VM_N_BLOCK, n_mem, algo);

  std::vector<std::vector<mem_block>> res;
  auto page_fault = vmModel.simulate(requests, res);
  print_helper(requests, page_fault, n_mem);
}

void test3() {
  printf("The algorithm is [OPT = 1 LRU = 2 FIFO = 3]:");
  int choice;
  ALGO algo;
  scanf("%d", &choice);
  switch (choice) {
  case 1:
    algo = OPT;
    break;
  case 2:
    algo = LRU;
    break;
  default:
    algo = FIFO;
  }
  printf("MEMORY\t\tMISS COUNT\tHIT RATE\n");

  for (int i = MIN_N_MEM; i <= MAX_N_MEM; i += STEP_N_MEM) {
    test3_helper(algo, TEST_SIZE, i);
  }
}